﻿using System;
using System.Collections.Generic;
using System.Text;
//new
using DataRecv.tools;
using DataRecv.db;
using System.Data;
using DataRecv.enums;
using System.Collections;

namespace DataRecv.models
{
    public class SnapParam
    {
        /// <summary>
        /// 表名称
        /// </summary>
        private const string c_TableName = "SnapParam_t";
        /// <summary>
        /// 字段集合
        /// </summary>
        private const string c_Columns = "snaptype,snapcount,platefrom,speedfrom,timefrom,otherfrom";
        /// <summary>
        /// 字段数量
        /// </summary>
        private const int c_ColumnsCount = 6;
        /// <summary>
        /// 抓拍类型
        /// </summary>
        public Enum_CaptureSystem snaptype;
        /// <summary>
        /// 抓拍张数
        /// </summary>
        public int snapcount;
        /// <summary>
        /// 车牌来自第几张
        /// </summary>
        public int platefrom;
        /// <summary>
        /// 车速来自第几张
        /// </summary>
        public int speedfrom;
        /// <summary>
        /// 时间来自第几张
        /// </summary>
        public int timefrom;
        /// <summary>
        /// 其他来自第几张
        /// </summary>
        public int otherfrom;

        public SnapParam()
        {
            snaptype = Enum_CaptureSystem.NONE;
            snapcount = 0;
            platefrom = 0;
            speedfrom = 0;
            timefrom = 0;
            otherfrom = 0;
        }

        /// <summary>
        /// 违法代码列表
        /// </summary>
        /// <returns>违法代码列表</returns>
        public static Hashtable GetModels()
        {
            Hashtable ans = ans = new Hashtable();
            DataTable dt = null;
            try
            {
                dt = DBHelper.GetInstance().Select(c_TableName, c_Columns, "1=1");
                if ((dt != null) && (dt.Rows != null) && (dt.Rows.Count > 0))
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        SnapParam sp = new SnapParam();
                        sp.snaptype = (Enum_CaptureSystem)Enum.Parse(typeof(Enum_CaptureSystem), row["snaptype"].ToString());
                        sp.snapcount = int.Parse(row["snapcount"].ToString());
                        sp.platefrom = int.Parse(row["platefrom"].ToString());
                        sp.speedfrom = int.Parse(row["speedfrom"].ToString());
                        sp.timefrom = int.Parse(row["timefrom"].ToString());
                        sp.otherfrom = int.Parse(row["otherfrom"].ToString());
                        ans.Add(sp.snaptype, sp);
                    }
                }
            }
            catch (Exception er)
            {
                ans = null;
                LogTool.log.Info("SnapParam.GetModels()" + er.Message);
            }
            finally
            {
                if (dt != null) dt.Dispose();
            }
            return ans;
        }


        public bool Save()
        {
            bool ans = false;
            try
            {
                string[] paramnames = c_Columns.Split(',');
                string[] paramvalues = new string[c_ColumnsCount];
                paramvalues[0] = snaptype.ToString();
                paramvalues[1] = snapcount.ToString();
                paramvalues[2] = platefrom.ToString();
                paramvalues[3] = speedfrom.ToString();
                paramvalues[4] = timefrom.ToString();
                paramvalues[5] = otherfrom.ToString();
                ans = DBHelper.GetInstance().EditorAddParam(c_TableName, paramnames, paramvalues);
            }
            catch { ans = false; }
            return ans;
        }
    }
}
